package com.logicalthinking.socialmall.controller.app;

import com.github.chenlijia1111.utils.common.Result;
import com.github.chenlijia1111.utils.core.annos.PropertyCheck;
import com.logicalthinking.socialmall.biz.MallProductBiz;
import com.logicalthinking.socialmall.common.vo.requestVo.product.AppFindProductInfoParams;
import com.logicalthinking.socialmall.common.vo.requestVo.product.AppProductQueryParams;
import com.logicalthinking.socialmall.common.vo.requestVo.product.MallProductAddParams;
import com.logicalthinking.socialmall.common.vo.requestVo.product.MallProductUpdateParams;
import com.logicalthinking.socialmall.common.vo.responseVo.product.AppProductListVo;
import com.logicalthinking.socialmall.common.vo.responseVo.product.SocialAppProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 产品控制器
 *
 * @author Chen LiJia
 * @since 2020/2/18
 */
@RestController(value = "appProductController")
@RequestMapping(value = "app/product")
@Api(tags = "产品")
@PropertyCheck
public class ProductController {


    @Autowired
    private MallProductBiz biz;//产品

    /**
     * 添加产品
     *
     * @param params
     * @return
     */
    @PostMapping(value = "add")
    @ApiOperation(value = "添加产品")
    public Result add(@RequestBody MallProductAddParams params) {
        return biz.add(params);
    }

    /**
     * 编辑产品
     *
     * @param params
     * @return
     */
    @PostMapping(value = "update")
    @ApiOperation(value = "编辑产品")
    public Result update(@RequestBody MallProductUpdateParams params) {
        return biz.update(params);
    }


    /**
     * 上架
     *
     * @param productId
     * @return
     */
    @PostMapping(value = "shelf/up")
    @ApiOperation(value = "上架")
    public Result shelfUp(String productId) {
        return biz.shelfUp(productId);
    }

    /**
     * 下架
     *
     * @param productId
     * @return
     */
    @PostMapping(value = "shelf/down")
    @ApiOperation(value = "下架")
    public Result shelfDown(String productId) {
        return biz.shelfDown(productId);
    }


    /**
     * 删除商品
     *
     * @param productId
     * @return
     */
    @PostMapping(value = "delete")
    @ApiOperation(value = "删除商品")
    public Result delete(String productId) {
        return biz.delete(productId);
    }

    /**
     * 客户端查询商品列表
     *
     * @param params
     * @return
     */
    @GetMapping(value = "listPage")
    @ApiOperation(value = "客户端查询商品列表", response = AppProductListVo.class)
    public Result appListPage(AppProductQueryParams params) {
        return biz.appListPage(params);
    }

    /**
     * 客户端查询商品详情
     *
     * @param params
     * @return
     */
    @GetMapping(value = "findById")
    @ApiOperation(value = "客户端查询商品详情", response = SocialAppProductVo.class)
    public Result appFindById(AppFindProductInfoParams params) {
        return biz.appFindById(params);
    }

}
